<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="entity.Utilisateur,login.LoginRemote,login.LoginBean,manager.UserManagerRemote,manager.UserManagerBean,javax.naming.*"%>

<%!
UserManagerRemote manager = null;
boolean connecte;
String infos="";
LoginRemote logger = null;

public void jspInit(){			
	
	try{
		InitialContext ic = new InitialContext();
		manager = (UserManagerRemote)ic.lookup(UserManagerBean.RemoteJNDIName);
		System.out.println("MANAGER:" + manager);
	}
	catch(Exception ex){ System.out.println("ERREUR!!" + ex.getMessage());}
}

	
public void jspDestroy(){
	manager=null;
	
}
%>
<%@page import="manager.UserManagerRemote;"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mastauc</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center>
<div style="width:800px;">

<div id="bandeau"><br/>MASTER AUCTION</div>

<div id="menu">
	<!-- DIV LOGIN -->
	<div id="menuhaut">
	<div id="entete">Login</div>
	<%
	
	String ulogin=request.getParameter("user_login");

	String umdp=request.getParameter("user_mdp");
	
	if (connecte && request.getParameter("loggedOff") != null)
	{
		if(logger!=null)
		{
			logger.logoff();
			System.out.println("logoff");
			connecte=false;	
		}
		
	}
	
	
	if(!connecte && ulogin!=null && umdp!=null && ulogin != "" && umdp != "")
	{		
		Utilisateur u = manager.check(ulogin,umdp);
		//LoginRemote logger = null;
		
		if (u!=null)
		{
			try{
				InitialContext ic = new InitialContext();
				logger = (LoginRemote)ic.lookup(LoginBean.RemoteJNDIName);
				System.out.println("LOGGER:" + logger);
			}
			catch(Exception ex){ System.out.println("ERREUR!!" + ex.getMessage());}
			
			logger.setUser(u);
			infos = logger.getInfos();
			
			if(logger!=null) connecte = true;
			
			
		}
		else
		{
			out.println("aucun utilisateur trouvé");
		}	
	
	}
	else
	{
		if (request.getParameter("submitted") != null)
		{
			out.println("champ saisi vide");
		}
	}
	
	
		
	if(!connecte)
	{
%>
	<form name="fautent" action="index.jsp" method="post">
	<table>
	<tr><td>Login:</td><td> <input type="text" name="user_login"/> </td></tr>
	<tr><td>Mot de passe:</td><td><input type="text" name="user_mdp"/>  </td></tr>
	<tr><td><input type="hidden" name="submitted" value="1"/></td><td><input type="submit" value=" ok " onclick="forms[0].submitted.value=1"/> </td></tr>
	</table>
	</form>
<%  }
	else
	{
		out.println(infos);
	
%>
	<form name="flogoff" method="post" action="index.jsp">
	<input type="submit" value="Déconnecter"/>	
	<input type="hidden" name="loggedOff" value="1"/>
	</form>
<%
	}
%>	

	</div>
	<!-- fin DIV LOGIN -->
	<div id="menubas">
	<div id="entete">Catégories</div>
	cat1<br/>
	cat2<br/>
	cat3<br/>
	</div>
<!--  
	<div id="menubas2">
	<div id="entete">Recherche</div>
	<br/><form name="fsearch" action="search.jsp" method="post">
	<input name="keyword" type="text"/> <input type="submit" value="ok"/>
	</form>
	</div>-->
</div>

<div id="contenu"><div id="entete"> 10 enchère(s) trouvée dans cat <b>cat1</b> : </div>Enchères en cours: <br/> </div>

<div id="piedpage">-Université Montpellier II - Master Auction </div>

</div>
</center>

</body>
</html>